﻿using System;
using System.Web.UI.WebControls;
using BLL;

public partial class ViewbyProduct_Interim_ViewbyUserIDDT : System.Web.UI.Page
{
    private Interim test;
    private string var_UserID
    {
        get { return ViewState["var_UserID"].ToString(); }
        set { ViewState["var_UserID"] = value; }
    }
    private DateTime dt1
    {
        get { return DateTime.Parse(ViewState["dt1"].ToString()); }
        set { ViewState["dt1"] = value; }
    }
    private DateTime dt2
    {
        get { return DateTime.Parse(ViewState["dt2"].ToString()); }
        set { ViewState["dt2"] = value; }
    }

    public ViewbyProduct_Interim_ViewbyUserIDDT()
    {
        test = new Interim();
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        var_UserID = this.TextBox1.Text.Trim();
        dt1 = DateTime.Parse(this.TextBox2.Text + " 00:00:00");
        dt2 = DateTime.Parse(this.TextBox3.Text + " 00:00:00");        
        this.Label1.Text = test.GetQbyUIDDT(var_UserID, dt1, dt2).ToString();
        BindTests();
    }

    protected void BindTests()
    {
        GridView1.DataSource = test.GetDebugTestsbyUIDDT(var_UserID, dt1, dt2);
        GridView1.DataBind();
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            if (GridView1.Rows[i].Cells[7].Text == "Fail")
                GridView1.Rows[i].Cells[7].ForeColor = System.Drawing.Color.Red;
        }
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        BindTests();
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["productSN"] = GridView1.SelectedDataKey["ProductSN"].ToString();
        Session["testTime"] = Convert.ToDateTime(GridView1.SelectedDataKey["TestTime"]);
        Session["ProductTypeID"] = GridView1.SelectedDataKey["ProductTypeID"].ToString();
        Session["UserID"] = GridView1.SelectedDataKey["UserID"].ToString();
        Session["ENAID"] = GridView1.SelectedDataKey["ENAID"].ToString();
        Session["SpecVersion"] = GridView1.SelectedDataKey["SpecVersion"].ToString();
        Session["IsPass"] = GridView1.SelectedDataKey["IsPass"].ToString();

        Response.Redirect("~/ViewTest/ViewYourself/ViewTestItem.aspx");
    }
}
